package com.bougaga.opensource.scheduler.core.task;

/**
 * 任务状态枚举
 * 
 * @author bougaga
 * @since 1.0.0
 */
public enum TaskStatus {
    
    /**
     * 等待中
     */
    PENDING("等待中"),
    
    /**
     * 执行中
     */
    RUNNING("执行中"),
    
    /**
     * 执行成功
     */
    SUCCESS("执行成功"),
    
    /**
     * 执行失败
     */
    FAILED("执行失败"),
    
    /**
     * 已取消
     */
    CANCELLED("已取消"),
    
    /**
     * 重试中
     */
    RETRYING("重试中"),
    
    /**
     * 超时
     */
    TIMEOUT("超时");
    
    private final String description;
    
    TaskStatus(String description) {
        this.description = description;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 判断任务是否已完成（不可再执行）
     */
    public boolean isCompleted() {
        return this == SUCCESS || this == FAILED || this == CANCELLED || this == TIMEOUT;
    }
    
    /**
     * 判断任务是否可以执行
     */
    public boolean canExecute() {
        return this == PENDING || this == RETRYING;
    }
    
    /**
     * 判断任务是否正在执行
     */
    public boolean isRunning() {
        return this == RUNNING;
    }
}
